
#include "bmp.h"

#define virt_printf printf

static short width = 212;
static short height = 104;

int main(int argc,char **argv)
{
    if(argc!=2)
    {
		virt_printf("please file name && path ");

        return 0;
    }

	// 1. create file    
    FILE *fp=fopen(argv[1],"wb");
    if(fp==NULL)
    {
        virt_printf("%s open file fail \n",argv[1]);
        return 0;
    }
    
	// 2. file header
	int cnt;
    struct _BMP_HEAD bmp_head;
    memset(&bmp_head,0,sizeof(struct _BMP_HEAD));
    bmp_head.type[0]='B';
    bmp_head.type[1]='M';
    bmp_head.size=54+width*height*3;
    bmp_head.seek=54;
    cnt=fwrite(&bmp_head,1,sizeof(struct _BMP_HEAD),fp);
    virt_printf("成功写入:%d 字节.\n",cnt);

    /*3. 写文件参数信息*/
    struct _BMP_INFO bmp_info;
    memset(&bmp_info,0,sizeof(struct _BMP_INFO));
    bmp_info.size=sizeof(struct _BMP_INFO);
    bmp_info.w=width;
    bmp_info.h=height;
    bmp_info.bit=24;
    bmp_info.flag=1;
    cnt=fwrite(&bmp_info,1,sizeof(struct _BMP_INFO),fp);
    virt_printf("成功写入:%d 字节.\n",cnt);

    /*4. 写入位图数据*/
    int w,h;
    int c=0xFF0033; //红色
    for(h=0;h<height;h++)
    {
        for(w=0;w<width;w++)
        {
            fwrite(&c,1,3,fp);
        }
        if(c != 0)
            c=0x000000;
        else
            c=0xFF0033;
    }
    /*5. 关闭文件*/
    fclose(fp);
    return 0;
}

